﻿/*
Description:锻造流水卡批量打印
Copyright (c) : 通力凯顿（北京）系统集成有限公司
Writer:zhangrj
create Date:
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BusinessRule.Business;
using BusinessRule.IBusiness;
using BusinessRule.BusinessFactory;
using BusinessRule.Common;
using DatabaseAccess.DBUtility;

public partial class forms_Custom_YePian_ContainerForgePrintForm : System.Web.UI.Page
{
    public string strHtml;//页面html
    public YPContainerBusiness ypBusiness = new YPContainerBusiness();
    public YPCommonBusiness common = new YPCommonBusiness();
    public List<Dictionary<string, object>> printSession;
    public DataTable dtMain;//批次基本信息
    public DataTable dtContainerStep;//工序信息
    public DataTable dtcontainerAttribute;//批次属性
    public DataTable dtSpecResource;//设备型号
    public DataTable dtSpecCheckPoints;//关键过程控制记录
    public DataTable dtContainerTemperature;//批次温度信息
    public DataTable dtContainerStepAttributes;//批次工序属性信息 add zhunan 2022.1.19
    //public DataTable dtContainerStepCheckNotes;//批次工序检验备注信息
    public DataTable dtContainerSubInfo;//批次的子批次信息
    public int pages = 0; //'页码（除去封面）
    int totalHeight = 1000;//一页的高度
    int rowHeight = 410;//起始行高，内容表头的
    int rowspan = 1; //合并单元格数'
    //系统根路径
    string path = "";
    public bool isBank = false;//是否空白
    public bool checkerNoEdit = true;
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)
            {
                path = Request.Url.AbsoluteUri.ToString().Substring(0, Request.Url.AbsoluteUri.IndexOf("forms")) + "ImageTemp/";
                printSession = (List<Dictionary<string, object>>)Session["PrintInfo"];
                Session.Remove("PrintInfo");
                if (printSession != null && printSession.Count > 0)
                {
                    for (int i = 0; i < printSession.Count; i++)
                    {
                        rowHeight = 401;//起始行高，内容表头的（工序）
                        pages = 0;//全局页码
                        rowspan = 1; //合并单元格数（工序） }//如果不是批量打印的第一个批次，则开始分页    
                        isBank = false;//是否空白
                        strHtml += InitData(printSession[i], i + 1 == printSession.Count ? true : false);
                    }
                }
                else
                {
                    string ContainerId = Request["ContainerId"];
                    string WorkflowId = Request["WorkflowId"];
                    string IsBlank = Request["IsBlank"];
                    if (string.IsNullOrEmpty(ContainerId) || string.IsNullOrEmpty(WorkflowId) || string.IsNullOrEmpty(IsBlank))
                    {
                        ClientScript.RegisterStartupScript(ClientScript.GetType(), "myScript", "<script>alert('刷新无效，请关闭后重新打印');</script>");
                        return;
                    }
                    Dictionary<string, object> printInfo = new Dictionary<string, object>();
                    printInfo["ContainerId"] = ContainerId;
                    printInfo["WorkflowId"] = WorkflowId;
                    printInfo["IsBlank"] = Boolean.Parse(IsBlank);
                    strHtml += InitData(printInfo, true);
                }

            }
        }
        catch (Exception ex)
        {
            Response.Write("<script type='text/javascript'>alert('系统报错：" + ex.Message + "');window.close();</script>");
        }
    }
    /// <summary>
    /// 初始化打印页面
    /// </summary>
    /// <param name="printInfo">打印信息</param>
    /// <param name="isLastContainer">是否最后一个批次</param>
    /// <returns></returns>
    private string InitData(Dictionary<string, object> printInfo, bool isLastContainer)
    {
        isBank = bool.Parse(printInfo["IsBlank"].ToString());
        var DP = ypBusiness.GetContainerPrintInfo(printInfo);
        dtMain = DP.Tables["dtMain"];//批次主信息
        dtcontainerAttribute = DP.Tables["containerAttributeDt"];//批次属性
        dtContainerStep = DP.Tables["dtContainerStep"];//批次工序列表
        dtSpecResource = DP.Tables["specResource"];//设备型号
        dtSpecCheckPoints = DP.Tables["dtCheckItemList"];//关键过程控制记录
        dtContainerTemperature = DP.Tables["dtContainerTemperature"];//批次温度信息
        dtContainerStepAttributes = DP.Tables["dtContainerStepAttributes"];//批次工序属性信息 add zhunan 2022.1.19
        //dtContainerStepCheckNotes = DP.Tables["dtContainerStepCheckNotes"];//批次工序检验备注信息
        dtContainerSubInfo = DP.Tables["dtContainerSubInfo"];//批次的子工艺批次信息
        //关键过程序多人报工时，只在最后一行显示关键过程信息
        #region 同一工序多条报工记录处理
        //checkerNoEdit: 检验员没有录入过实测值
        if (dtSpecCheckPoints.Rows.Count > 0)
        {
            checkerNoEdit = dtSpecCheckPoints.Select("containerstepworkreportid IS NOT NULL").Length == 0 ? true : false;
        }

        dtContainerStep = common.MergeContainerStepWorkReport(dtContainerStep, checkerNoEdit);
        #endregion

        string strCurrHtml = string.Empty;
        strCurrHtml = BindCover();//绑定封面    
        strCurrHtml += BindQualityProcedure();//绑定质量工序 
        strCurrHtml = strCurrHtml.Replace("=TPages=", pages.ToString());
        if (pages % 2 != 0 && !isLastContainer) //如果页面为基数,且不是最后一个批次
        {
            strCurrHtml += GetPaging() + GetPaging();
        }
        else
        {
            strCurrHtml += GetPaging();
        }
        return strCurrHtml;
    }

    #region 封面
    /// <summary>
    /// 初始化封面
    /// </summary>
    /// <returns></returns>
    private string BindCover()
    {
        DataRow drMain = dtMain.Rows[0];
        string strCover = string.Empty;
        string process_No = drMain["Process_No"].ToString();//工艺规程编号
        if (process_No.Contains("CZ"))
        {
            process_No = process_No.Replace("CZ", "");
        }
        strCover += GetPageHead(); ;//获取页眉
        //获取封面表格
        strCover += GetCoverTable(
            drMain["Part_RevID"].ToString(),//设计图版次
            //GetPartRev(drMain["firstusedproduct"].ToString()),//设计图版次
            drMain["ly2sequence"].ToString(),//工艺规程版
            process_No,//工艺规程编号
            drMain["mfgordername"].ToString(),//生产订单号
            string.IsNullOrWhiteSpace(drMain["YpHeatNo"].ToString()) ? "" : drMain["YpHeatNo"].ToString() + " " + drMain["YpContainerNo"].ToString(),//热处理批次号
            drMain["firstusedproduct"].ToString(),//零件图号（锻造不用取值productname）
            drMain["YpContainerNo"].ToString(),//锻批号
            drMain["YpContainerCardNo"].ToString(),//卡片号
            ""  //drMain["qty"].ToString()//数量
            );
        strCover += GetBarCode(drMain["containerid"].ToString(), drMain["mfgordername"].ToString());//获取条形码（订单号，批次ID）
        strCover += GetPaging();//分页
        return strCover;
    }

    /// <summary>
    /// 获取封面表格内容
    /// </summary>
    /// <param name="partRev">设计图版次</param>
    /// <param name="prosseRev">工艺规程版</param>
    /// <param name="prosseNum">工艺规程编号</param>
    /// <param name="orderNo">生产订单号</param>
    /// <param name="heatDealNo">热处理批次号</param>
    /// <param name="partDaringNo">零件图号</param>
    /// <param name="batchNo">段批号</param>
    /// <param name="batchNo">卡片号</param>
    /// <param name="qty">数量</param>
    /// <returns></returns>
    private string GetCoverTable(string partRev, string prosseRev, string prosseNum, string orderNo, string heatDealNo, string partDaringNo, string batchNo, string cardNo, string qty)
    {
        DataRow drMain = dtMain.Rows[0];
        string charactertype = drMain["charactertype"].ToString().Trim();
        string strHtml = string.Format(@"<table class='coverTable'>
                           <tr><td colspan='2' style='height:50px;'><span class='coverImportFile'>{0}</span></td></tr>", charactertype == "重要件" || charactertype == "关键件" ? charactertype : "");
        strHtml += @"<tr><td colspan='2' style='height:250px;text-align:center;'><span class='coverTitle'>流水作业卡</span><br /><div class='underLine' style='width: 325px; margin-left: 170px'></div></td></tr>";
        strHtml += string.Format(@"<tr><td class='coverTdTitle'><label class='coverLable'>{0}</label>{1}"
                   , GetCoverTableLable("设计图版次", 10), GetCoverTableData(partRev));
        strHtml += string.Format(@"<tr><td class='coverTdTitle'><label class='coverLable'>{0}</label>{1}"
                  , GetCoverTableLable("工艺规程版次", 4.4), GetCoverTableData(prosseRev));
        strHtml += string.Format(@"<tr><td class='coverTdTitle'><label class='coverLable'>{0}</label>{1}"
                  , GetCoverTableLable("工艺规程编号", 4.4), GetCoverTableData(prosseNum));
        strHtml += string.Format(@"<tr><td class='coverTdTitle'><label class='coverLable'>{0}</label>{1}"
                  , GetCoverTableLable("生产订单号", 9.7), GetCoverTableData(orderNo));
        strHtml += string.Format(@"<tr><td class='coverTdTitle'><label class='coverLable'>{0}</label>{1}"
                  , GetCoverTableLable("零件图号", 19), GetCoverTableData(partDaringNo));
        strHtml += string.Format(@"<tr><td class='coverTdTitle'><label class='coverLable'>{0}</label>{1}"
                  , GetCoverTableLable("锻批号", 37), GetCoverTableData(batchNo));
        strHtml += string.Format(@"<tr><td class='coverTdTitle'><label class='coverLable'>{0}</label>{1}"
                  , GetCoverTableLable("热处理批次号", 4.2), GetCoverTableData(heatDealNo));
        strHtml += string.Format(@"<tr><td class='coverTdTitle'><label class='coverLable'>{0}</label>{1}"
                  , GetCoverTableLable("卡片号", 37), GetCoverTableData(cardNo));
        strHtml += string.Format(@"<tr><td class='coverTdTitle'><label class='coverLable'>{0}</label>{1}"
                  , GetCoverTableLable("数量", 94), GetCoverTableData(qty));

        strHtml += string.Format(@"<tr><td colspan='2'></td></tr></table>
                     <table class='coverTable_Sub'><tr><td style='width: 150px'>备<br /><br />注<br /><br />栏</td><td>{0}</td></tr></table>", drMain["containercomments"]);
        return strHtml;
    }
    /// <summary>
    /// 获取封面数据（GetCoverTable方法的扩展方法）
    /// </summary>
    /// <param name="value"></param>
    /// <returns></returns>
    private string GetCoverTableData(string value)
    {
        return string.Format(@"<span class='coverSign'>:&nbsp;</span></td>
                  <td class='coverTdContent'><div class='coverContent'>{0}</div><div class='underLine'></div></td>
                  </tr>", value);
    }
    /// <summary>
    /// 获取封面字段名
    /// </summary>
    /// <param name="str"></param>
    /// <param name="index"></param>
    /// <returns></returns>
    private string GetCoverTableLable(string str, double index)
    {
        string strHtml = str[0].ToString();
        for (int i = 1; i < str.Length; i++)
        {
            strHtml += string.Format("<span style='margin-left:{0}px;'>{1}</span>", index, str[i].ToString());
        }
        return strHtml;
    }
    /// <summary>
    /// 获取条形码
    /// </summary>
    /// <param name="containId">流水号</param>
    /// <param name="mfgordername">订单号</param>
    /// <returns></returns>
    private string GetBarCode(string containId, string mfgordername)
    {
        if (string.IsNullOrWhiteSpace(mfgordername))
        {
            return string.Format("<div style='height:70px;'><div class=barCode style='float:Right'>*{0}*</div> <div style='clear:both'></div></div>", containId);
        }
        return string.Format("<div style='height:70px;'><div class=barCode style='float:left'>*{0}*</div><div class=barCode style='float:Right'>*{1}*</div></div>", containId, mfgordername);
    }

    /// <summary>
    /// 获取真正的设计图版次（只适用于锻造）
    /// </summary>
    /// <param name="productDaringNo"></param>
    /// <returns></returns>
    private string GetPartRev(string productDaringNo)
    {
        string sql = "";
        sql = @"select w.part_revid from product p
        left join productbase pb on pb.revofrcdid=p.productid 
        left join workflow w on w.workflowid=p.workflowid
        where pb.productname='{0}'";
        sql = string.Format(sql, productDaringNo);

        DataTable dt = DatabaseHelper.Query_ReturnDatTable(sql);
        return dt.Rows.Count > 0 ? dt.Rows[0][0].ToString() : "";
    }
    #endregion

    #region 质量工序
    /// <summary>
    /// 绑定质量工序
    /// </summary>
    /// <returns></returns>
    private string BindQualityProcedure()
    {
        string strProcedure = string.Empty;
        strProcedure += GetProcedureTable();//表格数据
        return strProcedure;
    }
    /// <summary>
    /// 获取质量工序内容表格
    /// </summary>
    /// <returns></returns>
    private string GetProcedureTable()
    {
        DataRow drMain = dtMain.Rows[0];
        string strTable = string.Empty;
        int containerStepCount = dtContainerStep.Rows.Count;//总的工序行数
        string originalstartdate = drMain["originalstartdate"].ToString();
        if (!string.IsNullOrWhiteSpace(originalstartdate))
        {
            originalstartdate = DateTime.Parse(originalstartdate).ToString("yyyy年MM月dd日");
        }
        string strTem = string.Empty;
        foreach (DataRow item in dtContainerTemperature.Rows)
        {
            if (item["temperaturename"].ToString() == "温度审签中" || item["temperaturename"].ToString() == "温度不维护")
            {
                continue;
            }
            strTem += item["temperaturename"].ToString() + ":" + item["temperaturevalue"].ToString() + ";";
        }

        //开始生成html页面
        strTable += GetPageHead();//页眉
        strTable += "<table class='forgeTitleTable'>";
        strTable += string.Format("<tr><td style='width: 80px'>计划员</td><td style='width: 140px'>{0}</td><td style='width: 80px'>建卡日期</td><td style='width: 140px'>{1}</td><td style='width: 80px'>检验员</td><td>{2}</td></tr>"
            , drMain["startemployeeName"].ToString()//计划员
            , originalstartdate//建卡日期
            , drMain["checkconfirmempName"].ToString());//检验员
        strTable += string.Format("<tr><td>材料牌号</td><td>{0}</td><td>材料标准</td><td>{1}</td><td>材料规格</td><td>{2}</td></tr>"
            , drMain["Materialtrademark"].ToString() //材料牌号
            , drMain["technicalconditions"].ToString() //材料标准（取的product中的技术条件）
            , drMain["materialspecification"].ToString());//材料规格
        strTable += string.Format("<tr><td>器材编号</td><td>{0}</td><td>钢厂炉号</td><td>{1}</td><td>实发数</td><td>{2}</td></tr>"
            , GetContainerAttr("检验编号") //器材编号（取值批次属性中的检验编号）
            , GetContainerAttr("熔炉号母") //钢厂炉号（取值批次属性中的熔炉号母）
            , GetContainerAttr("实发数/顺序号"));//实发数
        strTable += string.Format("<tr><td>代料牌号</td><td>{0}</td><td>代料规格</td><td>{1}</td><td>代料标准</td><td>{2}</td></tr>"
            , GetContainerAttr("代料牌号", true) //代料牌号
            , GetContainerAttr("代料规格", true) //代料规格
            , GetContainerAttr("代料标准", true));//代料标准
        strTable += string.Format("<tr><td>代料单号</td><td>{0}</td><td>例外放行<br/>审批单号</td><td>{1}</td><td>例外放行<br/>工艺规程编号/终止工序号</td><td>{2}</td></tr>"
            , GetContainerAttr("代料单号", true) //代料单号
            , GetContainerAttr("平行作业单号", true) //例外放行审批单号
            , GetContainerAttr("平行作业工序", true));//例外放行工序号
        strTable += string.Format("<tr><td>库房保管</td><td>{0}</td><td>器材检验</td><td>{1}</td><td>顾客代表</td><td>{2}</td></tr>"
            , GetContainerAttr("库房保管") //库房保管
            , GetContainerAttr("器材检验") //器材检验
            , GetContainerAttr("顾客代表"));//顾客代表
        strTable += string.Format("<tr><td colspan='4'><span style='float:left'>{0}</span></td><td>库存地点</td><td>{1}</td></tr>", strTem, drMain["lgort"].ToString());//加热温度，库存地点
        strTable += string.Format("<tr><td>主管技术员</td><td colspan='2'>{0}</td><td>日期</td><td colspan='2'>{1}</td></tr>"
            , string.IsNullOrWhiteSpace(strTem) ? "" : drMain["yptemperaempName"].ToString()
            , string.IsNullOrWhiteSpace(strTem) ? "" : drMain["yptemperaconfirmdate"].ToString());
        strTable += "</table>";
        //        strTable += string.Format(@"<table class='forgeTitleTable'><tr>
        //                                 <td>材料牌号</td><td style='width: 250px'>{0}</td>
        //                                 <td>建卡日期</td><td style='width: 250px'>{1}</td></tr>
        //                                 <tr><td>器材编号</td><td>{2}</td>
        //                                 <td>钢厂炉号</td><td>{3}</td></tr>
        //                                 <tr><td>计划员</td><td>{4}</td>
        //                                 <td>检验员</td><td>{5}</td></tr>
        //                                 <tr><td colspan='4'><span style='float:left'>{6}</span></td></tr>
        //                                 <td>主管技术员</td><td>{7}</td>
        //                                  <td>日期</td><td>{8}</td></tr></table>",
        //                                drMain["Materialtrademark"].ToString(), //材料号牌
        //                                originalstartdate,//建卡日期
        //                                drCheckNo != null ? drCheckNo["attributevalue"].ToString() : "",//器材编号
        //                                drFluNo != null ? drFluNo["attributevalue"].ToString() : "",//钢厂炉号
        //                                drMain["startemployeeName"].ToString(), //计划员
        //                                drMain["checkconfirmempName"].ToString(),//检验员
        //                                strTem,//加热温度
        //                                string.IsNullOrWhiteSpace(strTem) ? "" : drMain["yptemperaempName"].ToString(),//主管技术员
        //                                string.IsNullOrWhiteSpace(strTem) ? "" : drMain["yptemperaconfirmdate"].ToString());//日期
        strTable += GetProcedureTableTitle();//工序内容表头
        for (int i = 0; i < containerStepCount; i++)
        {
            DataRow dr = dtContainerStep.Rows[i];
            var isPages = IsPageing(dr);
            if (isPages.Item1)//判断是否分页
            {
                strTable += isPages.Item2;//添加空白行
                strTable += "</table>";
                strTable += GetPaging();//分页
                strTable += GetPageHead();//页眉
                strTable += GetProcedureTableTitle();//表头
            }
            if (dr["isSpotCheck"].ToString() == "1")//如果是关键工序
            {
                //strTable = GetRowSpan(strTable);//将之前的合并单元格
                strTable += GetProcedureTableContent(dr);//获取工序
                strTable += "</table>";
                strTable += common.SetSpecKeyQualityControl(dr["specid"].ToString(), dr["reportid"].ToString(), checkerNoEdit, dtSpecCheckPoints, dtSpecResource, dr);//获取关键工序html代码
                strTable += "<table class='forgeContentTable2'>";//更改表头样式
                //strTable += GetProcedureTableTitle(true);//获取隐藏的表头
            }
            else
            {
                strTable += GetProcedureTableContent(dr);
                rowHeight += 31;
            }
        }
        //数据结束后，如果没有布满一页，则补空行
        strTable += GetBlankRow();
        strTable += "</table>";
        return strTable;
    }

    #region 工序扩展方法
    /// <summary>
    /// 获取空白行
    /// </summary>
    /// <returns></returns>
    private string GetBlankRow()
    {
        string strh = string.Empty;
        for (int h = rowHeight + 31; h < totalHeight; h += 31)
        {
            strh += "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
        }
        return strh;
    }
    /// <summary>
    /// 合并单元格
    /// </summary>
    /// <param name="html"></param>
    /// <returns></returns>
    private string GetRowSpan(string html)
    {
        if (rowspan == 1)
            html = html.Replace("=rowmark=", "");
        else
            html = html.Replace("=rowmark=", String.Format(" rowspan='{0}'", rowspan));
        return html;
    }
    /// <summary>
    /// 是否需要分页
    /// </summary>
    /// <param name="dr"></param>
    /// <returns></returns>
    private Tuple<bool, string> IsPageing(DataRow dr)
    {
        string strBlank = string.Empty;
        if (rowHeight + 31 > totalHeight)//如果添加当前行高度后超过最大高度，则换页
        {
            rowHeight = 76;
            return new Tuple<bool, string>(true, strBlank);
        }
        if (dr["isSpotCheck"].ToString() == "1")
        {
            int processCount, designCount;
            if (checkerNoEdit)
            {
                processCount = dtSpecCheckPoints.Select(String.Format("specid='{0}' and checktype = '3'", dr["specid"].ToString())).Length;
                designCount = dtSpecCheckPoints.Select(String.Format("specid='{0}' and checktype = '4'", dr["specid"].ToString())).Length;
            }
            else
            {
                processCount = dtSpecCheckPoints.Select(String.Format("specid='{0}' and checktype = '3' and containerstepworkreportid = '{1}'",
                    dr["specid"].ToString(), dr["reportid"].ToString())).Length;
                designCount = dtSpecCheckPoints.Select(String.Format("specid='{0}' and checktype = '4' and containerstepworkreportid = '{1}'",
                    dr["specid"].ToString(), dr["reportid"].ToString())).Length;
            }
            processCount = processCount == 0 ? 1 : processCount;
            designCount = designCount == 0 ? 1 : designCount;

            //212 = 工序行31px + 关键过程控制记录表头31px + 设备型号及编号90px + 设计参数首行30px + 过程参数首行30px
            if ((rowHeight + 212 + (30 * (processCount + designCount))) > totalHeight)
            {
                strBlank = GetBlankRow();
                rowHeight = 76 + 212 + (30 * (processCount + designCount));
                return new Tuple<bool, string>(true, strBlank);
            }
            rowHeight += 212 + (30 * (processCount + designCount));
        }
        return new Tuple<bool, string>(false, "");
    }
    /// <summary>
    /// 获取工序表头
    /// </summary>
    /// <returns></returns>
    private string GetProcedureTableTitle()
    {
        return @"<table class='forgeContentTable'><tr><td rowspan='2' style='width:30px;'>工序号</td><td rowspan='2' style='width:150px'>工序名称</td><td rowspan='2' style='width:30px'>数量</td>
                    <td rowspan='2' style='width:50px'>操作者</td><td rowspan='2' style='width:100px'>日期</td><td colspan='4'>检验结果</td>
                    <td rowspan='2' style='width:70px'>首件批次号</td><td rowspan='2' style='width:50px'>检验印</td><td rowspan='2' style='width:100px'>备注</td></tr>
                    <tr><td style='width:30px'>合格</td><td style='width:30px'>报废</td><td style='width:30px'>返修</td><td style='width:30px'>超差</td></tr>";
    }
    /// <summary>
    /// 获取工序
    /// </summary>
    /// <param name="dr"></param>
    /// <param name="isSpan">是否属于合并项（该参数已废弃）</param>
    /// <returns></returns>
    private string GetProcedureTableContent(DataRow dr)
    {
        string containerId = dtMain.Rows[0]["containerId"].ToString();
        string strContent = "<tr>";
        string specno = dr["isSpotCheck"].ToString() == "1" ? "G" : "";//如果是关键工序，则在工序号前加G
        specno += dr["specno"].ToString();
        strContent += string.Format(@"<td style='width:30px'>{0}</td>", specno);//工序号
        strContent += string.Format(@"<td style='width:150px'>{0}</td>", dr["opdesc"].ToString());//工序名          
        strContent += string.Format(@"<td style='width:30px'>{0}</td>", isBank ? "" : dr["ReportQty"].ToString());//数量
        string reportEmployeeName = string.Empty;//操作工
        string checkemployeeName = string.Empty;//检验员
        string firstcheckcontainerno = string.Empty;//首件批次号
        string reportDate = string.Empty;//日期
        string notes = "";//备注
        if (!isBank)
        {
            //如果是检验序或者是外委序，则显示横线，否则显示操作者
            reportEmployeeName = dr["lastcheck"].ToString() == "1" || dr["controlcode"].ToString() == "LY05"
                ? "<div class='underLine' style='width: 30px;margin-left:10px'></div>" : dr["ReportEmployeeName"].ToString();
            //如果是外委序，则显示横线，否则显示检验员
            checkemployeeName = dr["controlcode"].ToString() == "LY05"
                ? "<div class='underLine' style='width: 30px;margin-left:10px'></div>" : dr["checkemployeename"].ToString();
            //日期不为空，则显示日期
            reportDate = !string.IsNullOrWhiteSpace(dr["reportdate"].ToString())
                ? DateTime.Parse(dr["reportdate"].ToString()).ToString("yyyy/MM/dd") : "";
            //如果报工了但没有首件批次号，则显示横线
            firstcheckcontainerno = !string.IsNullOrWhiteSpace(dr["ReportQty"].ToString()) && string.IsNullOrWhiteSpace(dr["firstcheckcontainerno"].ToString())
                ? "<div class='underLine' style='width: 50px;margin-left:10px'></div>"
                : dr["firstcheckcontainerno"].ToString().Replace(dtMain.Rows[0]["productname"].ToString() + "/", "");

            // 工序增加显示备注信息 add zhunan 2022.1.19
            if (dtContainerStepAttributes.Rows.Count > 0)
            {
                DataRow[] rows = dtContainerStepAttributes.Select(string.Format("workflowstepid='{0}'", dr["workflowstepid"].ToString()));
                foreach (DataRow item in rows)
                {
                    notes += item["notes"].ToString() + ",";
                }
            }
            //工人备注
            notes += string.IsNullOrWhiteSpace(dr["worknote"].ToString()) ? "" : dr["worknote"].ToString() + ",";
            //检验备注
            notes += string.IsNullOrWhiteSpace(dr["checknote"].ToString()) ? "" : dr["checknote"].ToString() + ",";
            //追加子批次信息
            if (dtContainerSubInfo.Rows.Count > 0)
            {
                DataRow[] rows = dtContainerSubInfo.Select(string.Format("workflowstepid='{0}'", dr["workflowstepid"].ToString()));
                foreach (DataRow item in rows)
                {
                    notes += item["rbtogetherflag"].ToString() + ",";
                }
            }
            ////备注追加工序检验备注信息 
            //if (dtContainerStepCheckNotes.Rows.Count > 0)
            //{
            //    DataRow[] rows = dtContainerStepCheckNotes.Select(string.Format("workflowstepid='{0}'", dr["workflowstepid"].ToString()));
            //    foreach (DataRow item in rows)
            //    {
            //        notes += item["checknote"].ToString() + ",";
            //    }
            //}
            if (dr["controlcode"].ToString() == "LY05" || dr["ISCOMMISSION"].ToString() == "1")//如果是外委
            {
                notes += "外委加工";
            }
            notes = notes.TrimEnd(',');
        }
        strContent += string.Format(@"<td style='width:50px'>{0}</td>", reportEmployeeName);//操作者
        strContent += string.Format(@"<td style='width:100px'>{0}</td>", isBank ? "" : reportDate);//日期
        strContent += string.Format(@"<td style='width:30px'>{0}</td>", isBank || dr["passqty"].ToString() == "0" ? "" : dr["passqty"].ToString());//合格数
        strContent += string.Format(@"<td style='width:30px'>{0}</td>", isBank || dr["lossqty"].ToString() == "0" ? "" : dr["lossqty"].ToString());//报废数
        strContent += string.Format(@"<td style='width:30px'>{0}</td>", isBank || dr["reworkqty"].ToString() == "0" ? "" : dr["reworkqty"].ToString());//返修数
        strContent += string.Format(@"<td style='width:30px'>{0}</td>", isBank || dr["defectqty"].ToString() == "0" ? "" : dr["defectqty"].ToString());//超差数
        strContent += string.Format(@"<td style='width:70px'>{0}</td>", firstcheckcontainerno);//首件批次号
        strContent += string.Format(@"<td style='width:50px'>{0}</td>", checkemployeeName);//检验员
        //备注
        if (notes != "" && notes.Length > 11)
        {
            strContent += string.Format(@"<td style='width:100px;font-size:10px;text-align:left;'>{0}</td></tr>", notes);
        }
        else
        {
            strContent += string.Format(@"<td style='width:100px;'>{0}</td></tr>", notes);
        }

        return strContent;
    }
    #endregion

    #endregion

    #region 通用方法
    /// <summary>
    /// 获取批次属性值
    /// </summary>
    /// <param name="attrValue">属性名</param>
    /// <param name="isDefault">空值是否默认横线（默认否）</param>
    /// <returns></returns>
    private string GetContainerAttr(string attrName, bool isDefault = false)
    {
        DataRow dr = dtcontainerAttribute.Select(string.Format("userattributename = '{0}'", attrName)).FirstOrDefault();
        string attrValue = dr != null ? dr["attributevalue"].ToString() : "";
        return string.IsNullOrWhiteSpace(attrValue) && isDefault ? "----" : attrValue;
    }
    /// <summary>
    /// 获取页眉
    /// </summary>
    /// <returns></returns>
    private string GetPageHead()
    {
        pages++;
        DataRow drMain = dtMain.Rows[0];
        string vision = "01";//版本
        if (!string.IsNullOrWhiteSpace(drMain["workflowrevision"].ToString()))//如果工艺版本不为空，则选择该版本
        {
            try
            {
                vision = int.Parse(drMain["workflowrevision"].ToString()) < 9 ? "0" + drMain["workflowrevision"].ToString() : drMain["workflowrevision"].ToString();
            }
            catch { }
        }
        else
        {
            if (!string.IsNullOrWhiteSpace(drMain["productrevision"].ToString()))//如果工艺版本为空，产品版本不为空，则选择该版本
            {
                try
                {
                    vision = int.Parse(drMain["productrevision"].ToString()) < 9 ? "0" + drMain["productrevision"].ToString() : drMain["productrevision"].ToString();
                }
                catch { }
            }
        }
        string strRight = string.Format("{0}-LK-{1}/=TPages=-V{2}", drMain["firstusedproduct"].ToString(), pages, vision);
        return String.Format("<table class='headTable'><tr><td style='text-align: left'>{0}</td><td style='text-align: right'>{1}</td></tr></table>", drMain["Process_No"].ToString(), strRight);
    }
    /// <summary>
    /// 获取分页
    /// </summary>
    /// <returns></returns>
    private string GetPaging()
    {
        return "<div class='paging'></div>";
    }
    #endregion
}